// Test for the flickr client
// Copyright 2006 (C) Ralph Thomas

#include <apps/photo/flickr.h>
#include <iostream>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <stdexcept>

namespace bfs = boost::filesystem;

//
// This test doesn't follow the template because it's interactive;
// it requires the tester to visit flickr's website.
//
int main() {
	char buf[1];
	try {
		std::string frob = flickr::get_frob();
		std::cout << "please visit: " << flickr::get_auth_url( frob ) << std::endl;
		std::cin.getline( buf, 1 );
		std::string token = flickr::get_token( frob );
		std::cout << "got token: " << token << std::endl;
		if( !flickr::check_token( token ) )
			std::cout << "ERROR: token invalid!" << std::endl;
		bfs::filebuf* fbuf = new bfs::filebuf();
		std::streambuf* sbuf = fbuf->open( bfs::path( "test.jpg", bfs::native ), std::ios_base::in | std::ios_base::binary );
		if( !sbuf ) { std::cout << "ERROR: no sbuf" << std::endl; return 0; }
		flickr::upload_photo( token, "Test Image", "This is a test image, uploaded by the Mission Photo flickr code", "mission", true, true, true, *sbuf );
	} catch( const std::exception& ex ) {
		std::cout << "ERROR: " << ex.what() << std::endl;
	}
	return 0;
}

